package o;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.serverreqkit.api.bean.BaseResponseBean;
import java.util.HashMap;
import java.util.Map.Entry;

public class dvs extends Handler {
    private dvn ˎ;

    static class b {
        private String ˊ;
        private int ˋ;
        private String ˎ;

        private b() {
            this.ˊ = null;
        }
    }

    public dvs(Looper looper, dvn o_dvn) {
        super(looper);
        this.ˎ = o_dvn;
    }

    public void handleMessage(Message message) {
        if (message.obj != null && (message.obj instanceof SessionDownloadTask)) {
            SessionDownloadTask sessionDownloadTask = (SessionDownloadTask) message.obj;
            switch (message.what) {
                case 1:
                    new dvu(sessionDownloadTask).ˏ();
                    return;
                case 4:
                    ˊ(sessionDownloadTask, 0);
                    return;
                case 5:
                    ˊ(sessionDownloadTask, -1);
                    return;
                default:
                    return;
            }
        }
    }

    private void ˊ(SessionDownloadTask sessionDownloadTask, int i) {
        if (sessionDownloadTask != null) {
            if (sessionDownloadTask.ˌ() == 9 || sessionDownloadTask.ˌ() == 10) {
                ˊ(sessionDownloadTask);
            } else if (!TextUtils.isEmpty(sessionDownloadTask.ॱˋ())) {
                cfw.ˎ(new dvk(sessionDownloadTask, i), this.ˎ);
            }
        }
    }

    private static void ˊ(final SessionDownloadTask sessionDownloadTask) {
        new Thread("bundleDownloadResultReport") {
            public void run() {
                dvj o_dvj = new dvj();
                cvt o_dvl = new dvl(sessionDownloadTask);
                for (Entry entry : dvs.ˋ(sessionDownloadTask).entrySet()) {
                    b bVar = (b) entry.getValue();
                    o_dvl.ॱ((String) entry.getKey());
                    o_dvl.ˎ(bVar.ˎ);
                    o_dvl.ˊ(bVar.ˋ);
                    o_dvl.ˏ(bVar.ˊ);
                    Logger.ˎ("CommonDownloadHandler", "packageName = " + sessionDownloadTask.ˊˊ() + "featureName = " + ((String) entry.getKey()) + ", featureTarget = " + bVar.ˎ + ", result = " + bVar.ˋ + ", reason = " + bVar.ˊ);
                    o_dvj.notifyResult(o_dvl, (BaseResponseBean) cfw.ॱ(o_dvl));
                }
            }
        }.start();
    }

    private static HashMap<String, b> ˋ(SessionDownloadTask sessionDownloadTask) {
        HashMap<String, b> hashMap = new HashMap();
        for (SplitTask splitTask : sessionDownloadTask.ᐝˊ()) {
            if (splitTask.ˊᐝ() != 1) {
                b bVar = (b) hashMap.get(splitTask.ॱˎ());
                if (bVar == null) {
                    bVar = new b();
                    bVar.ˎ = splitTask.ॱᐝ();
                    if (splitTask.ˊᐝ() == 0) {
                        bVar.ˋ = 0;
                    } else {
                        bVar.ˋ = 1;
                    }
                    hashMap.put(splitTask.ॱˎ(), bVar);
                } else if (splitTask.ˊᐝ() == -1) {
                    bVar.ˋ = 1;
                    bVar.ˊ = sessionDownloadTask.ˏॱ().toString() + ", url = " + splitTask.ͺ();
                    hashMap.put(splitTask.ॱˎ(), bVar);
                }
            }
        }
        return hashMap;
    }
}
